<?php
/*
 Install script - creates all tables for the database
 
 Michael Schwarz - 05.12.2010
*/

include("db.inc.php");

// user
db_query("CREATE TABLE  IF NOT EXISTS `absolventenv`.`user` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` TEXT NOT NULL ,
`pwd` TEXT NOT NULL ,
`mail` TEXT NULL
) ENGINE = MYISAM ;");


// add user admin / password
$r = db_query("SELECT * FROM user WHERE name='admin'");
if(($v = mysql_fetch_array($r)) == NULL) {
 db_query("INSERT INTO user (id, name, pwd, mail) VALUES ('', 'admin', 'ca7e1d48ffd6c43fc5c7c97416fe57d1bb4f8959', 'admin@admin.com')");
}

// settings
db_query("CREATE TABLE IF NOT EXISTS settings (
SettKey text NOT NULL,
SettValue text NOT NULL) ");

// news
db_query("CREATE TABLE IF NOT EXISTS  `absolventenv`.`news` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`subject` TEXT NOT NULL ,
`author` TEXT NOT NULL ,
`date` INT NOT NULL ,
`text` TEXT NOT NULL ,
`tags` TEXT NULL ,
`flags` INT NULL
) ENGINE = MYISAM ;");

$r = db_query("SELECT * FROM news WHERE id=1");
if(($v = mysql_fetch_array($r)) == NULL) {
 db_query("INSERT INTO news (id, subject, author, date, text, tags, flags) VALUES ('', 'Willkommen', 'Michael Schwarz', '1291642918', 'Willkommen auf der Seite des Absolventenvereins des BG/BRG Lichtenfels!', 'public|', '0')");
}

// permissions
db_query("CREATE TABLE IF NOT EXISTS `absolventenv`.`permissions` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`user` TEXT NOT NULL ,
`perm1` INT NULL ,
`perm2` INT NULL ,
`perm3` INT NULL
) ENGINE = MYISAM ;");

$r = db_query("SELECT * FROM permissions WHERE user='admin'");
if(($v = mysql_fetch_array($r)) == NULL) {
 db_query("INSERT INTO permissions (id, user, perm1, perm2, perm3) VALUES ('', 'admin', 2147483647, 0, 0)");
}

// messages
db_query("CREATE TABLE IF NOT EXISTS `absolventenv`.`messages` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`from` TEXT NOT NULL ,
`to` TEXT NOT NULL ,
`is_group` INT NOT NULL ,
`subject` TEXT NOT NULL ,
`text` TEXT NOT NULL ,
`date` INT NOT NULL ,
`flags` INT NOT NULL
) ENGINE = MYISAM ;");


?>
